package cn.kgc.service.impl;

import cn.kgc.mapper.ContactMapper;
import cn.kgc.pojo.Contact;
import cn.kgc.service.ContactService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import sun.util.locale.provider.FallbackLocaleProviderAdapter;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ContactServiceImpl implements ContactService {
    @Resource
    private ContactMapper contactMapper;
    @Override
    public PageInfo<Contact> findAllContact(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Contact>contactList = contactMapper.getAllContact();
        PageInfo<Contact>pageInfo = new PageInfo<>(contactList);
        return pageInfo;
    }

    @Override
    public PageInfo<Contact> findContactByName(String cname) {
        PageHelper.startPage(1,5);
        List<Contact>contactList = contactMapper.getContactByName(cname);
        PageInfo<Contact>pageInfo = new PageInfo<>(contactList);
        return pageInfo;
    }

    @Override
    public Contact findContactById(int id) {
        return contactMapper.getContactById(id);
    }

    @Override
    public boolean insertContact(Contact contact) {
        return contactMapper.addContact(contact)>0?true:false;
    }

    @Override
    public boolean modifyContactById(Contact contact) {
        return contactMapper.updContactById(contact)>0?true:false;
    }

    @Override
    public boolean removeContactById(int id) {
        return contactMapper.delContactById(id)>0?true: false;
    }
}
